#ifndef _SOCKET_TCPCLIENT_H_
#define _SOCKET_TCPCLIENT_H_

#include "socket.h"
#include "thread.h"

class CSyncTcpClient : public CSocket
{
public:

    CSyncTcpClient(){}
    
    virtual ~CSyncTcpClient(){}

    bool SetSocketInfo(const char* ip, ushort port);

    bool SyncWork(const char* inbuf, int inlen);

    virtual int OnRecvMsg(const char* inbuf, int inlen) = 0;

protected:

    virtual bool RecvMsg();
    
    virtual bool SendMsg(const char* inbuf, int inlen);
};

class CTcpClient : public CSocket
{
    friend THREAD_HANDLE(tcpclient_work_thread, param);

public:

    CTcpClient(bool isrecon = false);
    
    virtual ~CTcpClient();

    virtual bool OnSendMsg(SendBuffer* sendbuf);
    
    virtual int OnRecvMsg(const char* inbuf, int inlen) = 0;

    virtual bool StartSocket(const char* ip, ushort port);

protected:

    virtual bool RecvMsg();

    virtual bool SendMsg();

private:

    void Clean();

    void WorkThread();

    bool    m_isrun;

    bool    m_isrecon;

    CThread m_workthread;

    SendBufferQueue m_sendqueue;
};


#endif //_SOCKET_TCPCLIENT_H_
